<?php

namespace Home\Controller;
use Think\Controller;

class GuessController extends BaseController{
	
	public function index(){
		$this->display();
	}
	public function betting()
	{
		$user = session('user');
		if(IS_POST){
			   
				$integral = I('integral');
				if($integral!="")
				{
					       $res = check_format($integral);
		                    if($res['error']==0){
		                    	$this->error('单笔点数最低20,竞猜失败');
							    }else if($res['type']){

								$jifen = M('user')->where("id = {$user['id']}")->find();

								if($jifen['points']<$res['points']){
									

								}else{
									$user2 = M('user')->where("id = {$user['id']}")->find();
		    						$map['userid'] = $user2['id'];
									$map['number'] = F('pk10_No')+1;
									$map['type'] = $res['type'];
									$map['state'] = 1;
									$map['time'] = time();
									$map['jincai'] = $integral;
									$map['is_add'] = 0;
									$map['add_points'] = 0;
									$map['del_points'] = $res['points'];
									$map['balance'] = $user2['points']-$map['del_points'];
									$map['nickname'] = $user2['nickname'];
									$res2 = M('order')->add($map);

									if($res2){
										/*减分*/
										$res_points = M('user')->where("id = {$user['id']}")->setDec('points',$map['del_points']);
										$this->redirect('Home/Guess/index');
									}
								}
                            }else{
                            	
                            	$this->error('格式不正确,竞猜失败:'.$integral);

                            }

    						
							// var_dump($res);
				}
			}
	}
	
	
	
	
	
}



?>